//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static void main(String[] args) {
        //1.BM32合并二叉树
        public TreeNode mergeTrees (TreeNode t1, TreeNode t2){
            if (t1 == null && t2 == null) {
                return null;
            }
            if (t1 == null & t2 != null) {
                return t2;
            }
            if (t1 != null & t2 == null) {
                return t1;
            }
            TreeNode head = new TreeNode(t1.val += t2.val);
            head.left = mergeTrees(t1.left, t2.left);
            head.right = mergeTrees(t1.right, t2.right);
            return head;
        }
        //2.BM46最小的k个数
        public ArrayList<Integer> GetLeastNumbers_Solution ( int[] input, int k){
            PriorityQueue<Integer> p1 = new PriorityQueue<Integer>();
            ArrayList<Integer> array = new ArrayList<Integer>();
            for (int i = 0; i < input.length; i++) {
                p1.offer(input[i]);
            }
            for (int i = 0; i < k; i++) {
                array.add(p1.poll());
            }
            return array;
        }
        //3.BM32数组中出现次数超过一半的数字
        public int MoreThanHalfNum_Solution ( int[] numbers){
            int ret = numbers[0];
            int count = 1;
            for (int i = 1; i < numbers.length; i++) {
                if (ret == numbers[i]) {
                    count++;
                } else {
                    count--;
                }
                if (count == 0) {
                    ret = numbers[i + 1];
                }
            }
            return ret;
        }
    }
}